package com.zff.rental.utils;

/**
 * @author HCY
 */
public class WGS84Utils {
    private static final double EARTH_RADIUS = 6378137;

    public static Double getDistance(Double latitude1, Double longitude1, Double latitude2, Double longitude2) {
        if (latitude1 == null || longitude1 == null || latitude2 == null || longitude2 == null) {
            return null;
        }
        longitude1 = longitude1 * Math.PI / 180.0;
        longitude2 = longitude2 * Math.PI / 180.0;
        double a = longitude1 - longitude2;
        double b = (latitude1 - latitude2) * Math.PI / 180.0;
        double sa2 = Math.sin(a / 2.0);
        double sb2 = Math.sin(b / 2.0);
        return 2 * EARTH_RADIUS * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(longitude1) * Math.cos(longitude2) * sb2 * sb2));
    }
}
